<template>
    <div @click="closeGallary">
        <div class="common_gallary">
            <div class="slide-fullpage">
                <div class="banner-wrapper">
                    <div class="slide-banner-wrapper" ref="slide">
                        <div class="slide-banner-content">
                            <img :src="item.img_url" alt="#" v-for="item in img_list" :key="item.id">
                        </div>
                        <div class="slide-banner-content">
                            <img :src="item.img_url" alt="#" v-for="item in img_list" :key="item.id">
                        </div>
                    </div>
                    <div class="dots-wrapper">
                        <span class="dot" v-for="num in nums" :key="num"
                            :class="{'active': currentPageIndex === (num - 1)}"></span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
  
<script>
import BScroll from '@better-scroll/core'
import Slide from '@better-scroll/slide'

BScroll.use(Slide)

export default {
    data() {
        return {
            nums: 2,
            currentPageIndex: 0,
            img_list: [
                {
                    id: 1,
                    img_url: 'http://img1.qunarzz.com/sight/p0/1709/76/7691528bc7d7ad3ca3.img.png_800x800_9ef05ee7.png'
                }, {
                    id: 2,
                    img_url: 'http://img1.qunarzz.com/sight/p0/201404/23/04b92c99462687fa1ba45c1b5ba4ad77.jpg_800x800_70debc93.jpg'
                }
            ]
        }
    },
    mounted() {
        this.init()
    },
    beforeDestroy() {
        this.slide.destroy()
    },
    methods: {
        init() {
            window.slide = this.slide = new BScroll(this.$refs.slide, {
                scrollX: true,
                scrollY: false,
                slide: {
                    threshold: 100,
                    loop: true,
                    autoplay: false
                },
                useTransition: false,
                momentum: false,
                bounce: false,
                stopPropagation: true,
                click:true,
            })
            this.slide.on('scrollEnd', this._onScrollEnd)
        },
        nextPage() {
            this.slide.next()
        },
        prePage() {
            this.slide.prev()
        },
        _onScrollEnd() {
            let pageIndex = this.slide.getCurrentPage().pageX
            this.currentPageIndex = pageIndex
        },
        closeGallary(){
            this.$emit('close');
        }
    }
}
</script>
  
<style lang="scss" scoped>
.common_gallary {
    z-index: 999;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #000000;

    display: flex;
    flex-direction: column;
    justify-content: center;
    align-content: center;
}


$color_1: #fff;
$background-color_1: #95b8d1;
$background-color_2: #dda789;
$background-color_3: #c3d899;
$background-color_4: #f2d4a7;
$background-color_5: #666;

.slide-fullpage {
    height: 100%;

    .banner-wrapper {
        position: relative;
        height: 100%;
    }

    .slide-banner-wrapper {
        height: 100%;
        overflow: hidden;
    }

    .slide-banner-content {
        height: 100%;
        white-space: nowrap;
        font-size: 0;
        margin-top: 230px;

        .slide-page {
            display: inline-block;
            height: 100%;
            width: 100%;
            line-height: 200px;
            text-align: center;
            font-size: 26px;
            transform: translate3d(0, 0, 0);
            backface-visibility: hidden;
        }

        .slide-page.page1 {
            background-color: $background-color_1;
        }

        .slide-page.page2 {
            background-color: $background-color_2;
        }

        .slide-page.page3 {
            background-color: $background-color_3;
        }

        .slide-page.page4 {
            background-color: $background-color_4;
        }
    }

    .dots-wrapper {
        position: absolute;
        bottom: 4px;
        left: 50%;
        transform: translateX(-50%);

        .dot {
            display: inline-block;
            margin: 0 4px;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: #eee;
        }

        .dot.active {
            width: 20px;
            border-radius: 5px;
        }
    }

    .btn-wrap {
        margin-top: 20px;
        display: flex;
        justify-content: center;

        button {
            margin: 0 10px;
            padding: 10px;
            color: $color_1;
            border-radius: 4px;
            background-color: $background-color_5;
        }
    }
}

.slide-fullpage.view {
    padding: 0;
    height: 100%;
}
</style>